import 'package:flutter/material.dart';
import 'package:socket_io_client/socket_io_client.dart' as IO;

class Test extends StatefulWidget {
  Test({Key key}) : super(key: key);

  @override
  _TestState createState() => _TestState();
}

class _TestState extends State<Test> {
  // IO.Socket socket = IO.io(
  //     'http://192.168.0.9:3002',
  //     IO.OptionBuilder().setTransports(['websocket']) // for Flutter or Dart VM
  //         // .setExtraHeaders({'foo': 'bar'}) // optional
  //         .build());

  TextEditingController _controller = TextEditingController();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    // socket.onConnect((_) {
    //   print('connect');
    //   socket.emit('message', 'test');
    // });
    // socket.on('greeting', (data) => print(data));
    // socket.onDisconnect((_) => print('disconnect'));
    // socket.on('fromServer', (_) => print(_));
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey.shade400,
      appBar: AppBar(
        title: Text("New route"),
      ),
      body: Container(
        color: Colors.orange.shade100,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            // FlatButton(
            //   onPressed: () {
            //     Navigator.pushNamed(context, 'new_page');
            //   },
            //   child: Text('open a new route'),
            //   textColor: Colors.blue,
            // ),
            // FlatButton(
            //   onPressed: () async {
            //     var result = await Navigator.of(context)
            //         .pushNamed('tip2', arguments: '订单号1234565');
            //     print(result);
            //   },
            //   child: Text('带参路由'),
            // ),
            Form(
              child: TextFormField(
                controller: _controller,
                decoration: InputDecoration(labelText: 'Send a message'),
              ),
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _sendMessage,
        tooltip: 'send message',
        child: Icon(Icons.send),
      ),
    );
  }

  void _sendMessage() {
    if (_controller.text.isNotEmpty) {}
  }
}
